package homework917;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;

public class CollectionDemo_Homework {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        boolean b = c.add("one");
        System.out.println(b);
        System.out.println(c);
        System.out.println(c.size());
        System.out.println(c.isEmpty());
        System.out.println(c.contains("one"));

        c.clear();
        System.out.println(c);
        System.out.println(c.size());
        System.out.println(c.isEmpty());

        Collection c1 = new ArrayList();
        c1.add(new Point(1,2));
        c1.add(new Point(3,4));
        c1.add(new Point(5,6));
        c1.add(new Point(7,8));
        c1.add(new Point(9,10));
        boolean b1 = c1.add(new Point(11,12));
        System.out.println(b);
        System.out.println(c1);

        Point p = new Point(11,12);
        boolean contains = c1.contains(p);
        System.out.println(contains);

        boolean b2 = c1.remove(p);
        System.out.println(b2);

        Collection c2 = new ArrayList();
        c2.add(p);
        System.out.println(p);
        System.out.println(c);

        p.setX(100);
        System.out.println(p);
        System.out.println(c);

        c1.addAll(c2);
        System.out.println(c1);
        System.out.println(c2);

        Collection c3 = new ArrayList();
        c3.add(new Point(1,2));

        c1.removeAll(c3);
        System.out.println(c1);
        System.out.println(c3);

        Collection<String> c4 = new ArrayList<>();
        c4.add("one");
        c4.add("two");
        c4.add("three");
        c4.add("four");
        c4.add("five");
        //c4.add(123);

        //NewFor
        for (String s : c4) {
            System.out.println(s);
        }


        //迭代器
        Iterator<String> it = c4.iterator();
        while(it.hasNext()){
            String s = it.next();
            System.out.println(s);
        }


        //CollectionToArray
        String[] arr = c4.toArray(new String[10]);
        System.out.println(Arrays.toString(arr));




    }
}
